/*
 * Copyright (C) 2011 Macambira Team
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package com.googlecode.register;

import java.util.LinkedList;
import java.util.List;

/**
 * Classe responsavel por realizar o CRUD de turma
 * 
 * @version 0.1 29 Set 2011
 * @author Tony Silva | tony.silva@dce.ufpb.br
 */
public class ControlTurma {
    
    private List<Turma> listTurmas;
    
    public ControlTurma() {
        listTurmas = new LinkedList<Turma>();
    }
    
    public void addTurma(Turma turma) {
        this.listTurmas.add(turma);
    }
    
    public List<Turma> getTurma() {
        return this.listTurmas;
    }
    
    public Turma getTurmaId(String id) {
        for(Turma t : listTurmas) {
            if(t.getId().equalsIgnoreCase(id)) {
                return t;
            }
        }
        return null;
    }
    
    public Turma getTurmaNome(String nome) {
        for(Turma t : listTurmas){
            if(t.getNome().equalsIgnoreCase(nome)) {
                return t;
            }
        }
        return null;
    }
    
    public void removerTurmaNome(String nome) {
        for(Turma t : listTurmas) {
            if(t.getNome().equalsIgnoreCase(nome)) {
                this.listTurmas.remove(t);
                break;
            }
        }
    }
    
    public void removerTurmaId(String id) {
        for(Turma t : listTurmas) {
            if(t.getId().equalsIgnoreCase(id)) {
                this.listTurmas.remove(t);
                break;
            }
        }
    }
    
    public void updateTurma(Turma turma) {
        for(Turma t : listTurmas) {
            if(t.getId().equalsIgnoreCase(turma.getId())); {
                removerTurmaId(turma.getId());
                this.listTurmas.add(turma);
                break;
            }
        }
    }
    
    public int getSize() {
        return listTurmas.size();
    }
}
